<?php
require_once('Db.php');
require_once('Category.php');
require_once('School.php');
require_once('Answer.php');
require_once('Question.php');
require_once('Form.php');
Db::init();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>
Free Open-Source software na školách
</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="jquery-1.5.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
  function init(){
    $('.other_switcher').change(function(){
      $('#'+$(this).attr('name')).fadeToggle().focus();
    });
    $('input:radio').change(function(){
      var input_name = $(this).attr('name');
      var checked = $('input[@name='+input_name+']:checked');
      var sub_answer_id = $(checked).attr('id').substr(7);
      if($('#'+sub_answer_id).length>0)
      {
        $('#'+sub_answer_id).fadeIn();
      }
      var unchecked = $('input[@name='+input_name+'][checked=false]');
      var sub_answer_id = $(unchecked).attr('id').substr(7);
      if($('#'+sub_answer_id).length>0)
      {
        $('#'+sub_answer_id).fadeOut();
      }
    });
  }
  
  function close(){
    $.ajax({
      url:"?action=close&school_id=<?php echo $_REQUEST['school_id'];?>"
    });
  }
</script>
</head>
<body onload="init()" onunload="close()">
<img src="bg.gif" alt=""/><br/>
<div id="center_div">
  <h1>Prieskum používanosti otvoreného softvéru v školstve</h1>
  <?php
    $school = new School();
    if(empty($_REQUEST['school_id']))
    {
      die('Chýba parameter school_id');
    }
    if(!empty($_REQUEST['action']) && $_REQUEST['action']=='close')
    {
      $school->loadFromHash($_REQUEST['school_id'])->log("close");
      die;
    }
    if(!empty($_POST['submit']))
    {
      $school->loadFromHash($_REQUEST['school_id'])->createForm()->processPost($_POST);
    }
    else
    {
      try
      {
        echo $school->loadFromHash($_REQUEST['school_id'])->createForm()->render();
      }
      catch(Exception $e)
      {
        die("Chyba.");
      }
    }
  ?>
</div>
</body>
</html>
<?php
  Db::close();
?>
